home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
switch.zip
/
SWM.C
< prev
next >
Wrap
Text File
|
1993-01-04
|
12KB
|
452 lines
/*
Switch! Copyright (C)1988-1989 By Curtis Little
All Rights Reserved
Window Captain Jr. Library Copyright (C)1987-1989 By Curtis Little
All Rights Reserved
YOU SHOULD SET YOUR TAB SIZE TO FOUR IF YOU WANT TO EDIT THIS!
NOTE: This program has been compiled and works with MSC and Turbo C.
It may work with other compilers, but I haven't tried to check.
*/
extern unsigned Vcol; /* references to my screen handler funcs */
extern unsigned Vline;
extern unsigned Color;
#include <stdio.h>
#include <string.h>
int Center( int mrow, int attr, char *mstr );
int SetScreen( void );
int PressAnyKey( void );
int CenterBox( int mheight, int mwidth );
#define NUMFIELDS 4
#define USE_VALID 1
#define UPPER_ONLY 4
#define YN_ONLY 8
#define POS_ONLY 16
#define INT_ONLY 32
#define DONT_INIT 64
static int trow=0, lcol=0, brow=0, rcol=0, UserP=0;
static char mcommand[48], mpath[48], mmbuf[4], mrbuf[2];
static int msize[NUMFIELDS] = { 46, 46, 3, 1 };
static int mvali[NUMFIELDS] = { 0, UPPER_ONLY, INT_ONLY | POS_ONLY, YN_ONLY };
static char *mptr[NUMFIELDS] = { mcommand, mpath, mmbuf, mrbuf };
#define BLUE 1
#define WHITE 15
#define LIGHTGRAY 7
#define RED 4
#define CYAN 3
#define OFF 0
#define ON 1
#define TXCOLOR (BLUE << 4) | LIGHTGRAY
#define TXCOLORH TXCOLOR ^ 8
#define ESCAPE 1
#define UP_ARROW 2
#define K_TAB 0x0f09
#define K_BACKTAB 0x0f00
#define K_DOWN 0x5000
#define K_UP 0x4800
#define K_BACKTAB 0x0f00
#define say(x, y, z) v_putsa( (x), (y), TXCOLOR, (z) ); trow = x
void *malloc( );
void cdecl v_putsa( int row, int col, int attr, char *string );
void cdecl v_init( void );
void cdecl v_cursor( int flag );
void cdecl v_clw( int top, int left, int bottom, int right, int attr );
void cdecl v_drawbox( int top, int left, int height, int width, int attr );
void cdecl v_putcur( int row, int col );
void cdecl v_cls( void );
void cdecl v_saveblock( int top, int left, int height, int width, char *buff );
void cdecl v_restblock( int top, int left, int height, int width, char *buff );
char *v_gets( int row, int col, int attr1, int attr2, int length, char *buf, int flag, ... );
void cdecl v_fillca( int row, int col, int attr, int chara, int num );
void cdecl v_putca( int row, int col, int attr, int chara );
void cdecl v_keyflush( void );
char *ActiveWindow = NULL;
int check_arrow( int status, int key, int fieldcode )
{
if (status == 1) {
UserP = ESCAPE;
return(2);
}
if (key == K_UP || key == K_BACKTAB) {
UserP = UP_ARROW;
return(4);
}
UserP = 0;
if (key == K_TAB || key == K_DOWN) {
return(4);
}
return(2);
}
int main( void )
{
int merror, mrestore, mmem, mfield;
char *mtemp, *mscreen;
char buf[80], buf1[80];
/* initialize the variables */
merror = mrestore = mmem = 0;
if ((mscreen=(char *)malloc(Vline * Vcol * 2))==NULL) {
printf( "Not enough memory\n" );
exit(1);
}
/* initialize the screen functions */
v_init();
if (Vline > 25) {
Vline = 25; /* library for this demo has been limited */
/* to work in 80x25 mode only! */
}
if (Vcol != 80) {
printf( "\nERROR: Must be in 80x25 mode for this demo.\n" );
exit(1);
}
v_setbox( "╔═╗║╝═╚║" );
mcommand[0] = mpath[0] = '\0';
mtemp = NULL;
/* display the main screen used by this demo program */
SetScreen();
v_cursor( OFF );
/* now display the first advertisement box */
CenterBox( 16, 69 );
say( trow + 4,lcol + 4, "Introducing Switch!. Switch! is a UDF designed to make your" );
say( trow+1, lcol + 4, "programming life easier. Switch! allows you to run any size" );
say( trow+1, lcol + 4, "program from within your C and Assembler applications." );
say( trow+2, lcol + 4, "Switch! makes this possible by saving the memory used by your" );
say( trow+1, lcol + 4, "program to disk or EMS, and then freeing it making the memory" );
say( trow+1, lcol + 4, "available to execute any standard DOS command line you specify." );
say( trow+2, lcol + 4, "This demonstration program lets you see what Switch! does for" );
say( trow+1, lcol + 4, "you. Press any key to move on." );
v_keyflush();
PressAnyKey();
/* display the second ad box */
CenterBox( 23, 69 );
say( trow + 4,lcol + 4, "Switch! has the following features:" );
say( trow+2, lcol + 4, "» Works with disk or EMS (3.2+)" );
say( trow+2, lcol + 4, "» Automatic detection of unsafe interrupts." );
say( trow+2, lcol + 4, "» Automatically saves ALL interrupt addresses and then restores" );
say( trow+1, lcol + 4, " them when the child program is finished." );
say( trow+2, lcol + 4, "» Allows you to specify the drive and/or path for the file." );
say( trow+2, lcol + 4, "» Built in fatal error handler." );
say( trow+2, lcol + 4, "» Saves extended file handle table." );
say( trow+2, lcol + 4, "» Allows you to get the error level of the child process." );
say( trow+2, lcol + 4, "» And a whole lot more, but I ran outta space here! <grin>" );
PressAnyKey();
SetScreen();
/* display the main data entry box */
CenterBox(17, 73);
v_putca( trow + 12, lcol, TXCOLORH, 199 );
v_putca( trow + 14, lcol, TXCOLORH, 199 );
v_putca( trow + 12, rcol, TXCOLORH, 182);
v_putca( trow + 14, rcol, TXCOLORH, 182);
v_fillca( trow + 12, lcol + 1, TXCOLORH, 196, 71 );
v_fillca( trow + 14, lcol + 1, TXCOLORH, 196, 71 );
Center( trow + 12, (CYAN << 4), " Last Switch! Result " );
Center( Vline - 1, (CYAN << 4), " Press ESCape to Quit " );
/* loop to process user input until ESCape is pressed */
while (1) {
/* Now display the demo input screen */
mrestore = getrestdir();
strcpy( mrbuf, mrestore ? "Y" : "N" );
if( childret() == -1)
mtemp = "N/A";
else {
mtemp = buf;
sprintf( buf, "%d ", childret() );
}
sprintf( buf1, "Child returned error level: %s", mtemp );
v_putsa( trow + 13, lcol + 2, TXCOLOR, buf1 );
/*
Process the error value returned by Switch! now.
*/
switch( merror ) {
case 0:
mtemp = " - No problem! Everything's cool. ";
break;
case 8:
mtemp = " - Not enough memory. ";
break;
case 3:
mtemp = " - How wierd, I couldn't free memory. ";
break;
case 4:
mtemp = " - Too many files are already open! ";
break;
case 5:
mtemp = " - Access denied? DOS is talking back ";
break;
case 6:
mtemp = " - Can't find COMMAND.COM! ";
break;
case 10:
mtemp = " - No space! (Delete something?) ";
break;
case 11:
mtemp = " -You'll have to buy the drive first. ";
break;
case 12:
mtemp = " - Unable to write the file. ";
break;
case 14:
mtemp = " - Whoa! Too many handles! I do 255. ";
break;
case 15:
mtemp = " - The specified path is imaginary! ";
break;
case 16:
mtemp = " - Specified file exists! OVWR is OFF!";
break;
default:
if (merror > 255 ) {
sprintf( buf1, " - Interrupt %xh would be unsafe!", merror / 256 );
mtemp = buf1;
}
else
mtemp = " - I don't EVEN know what went wrong! ";
}
sprintf( buf, "Last Switch! return value: %d%s", merror, mtemp );
v_putsa( trow + 15, lcol + 3, TXCOLOR, buf );
v_putsa( trow + 8, lcol + 29, TXCOLOR, "(0 for ALL)" );
v_putsa( trow + 4, lcol + 7, TXCOLOR, "Program to Run:" );
v_putsa( trow + 4, lcol + 24, TXCOLOR, mcommand );
v_putsa( trow + 6, lcol + 3, TXCOLOR, "Path for Temp File:" );
v_putsa( trow + 6, lcol + 24, TXCOLOR, mpath );
v_putsa( trow + 8, lcol + 4, TXCOLOR, "K Memory Required:" );
v_putsa( trow + 8, lcol + 24, TXCOLOR, mmbuf );
v_putsa( trow +10, lcol + 4, TXCOLOR, "Restore Drive/Dir:" );
v_putsa( trow + 10, lcol + 24, TXCOLOR, mrbuf );
mfield = 0;
sprintf( mptr[2], "%d", mmem );
UserP = 0;
v_cursor( ON );
while (1) {
v_gets( trow + 4 + (mfield * 2), lcol + 24, LIGHTGRAY << 4,
TXCOLOR, msize[mfield], mptr[mfield], mvali[mfield] | DONT_INIT | USE_VALID,
check_arrow );
if (UserP == ESCAPE)
break;
if (mfield == 2)
mmem = atoi( mptr[mfield] );
/* now process the next field to go to */
if (UserP == UP_ARROW) {
mfield--;
if (mfield < 0)
mfield = 0;
}
else {
mfield++;
if (mfield == NUMFIELDS)
break;
}
}
/* did user ESCape out? */
if (UserP == ESCAPE)
break;
mrestore = (mrbuf[0] == 'Y') ? 1 : 0;
/* set the restore directory flag */
setrestdir(mrestore);
/* save the screen to restore after the shell */
v_saveblock( 1, 1, Vline, Vcol, mscreen );
v_cls();
/* Switch! out memory now. It's that magic time! */
merror = switch_( mpath, mmem, mcommand );
/* restore the screen */
v_restblock( 1, 1, Vline, Vcol, mscreen );
}
/* Finally print the last screen to finish up */
SetScreen();
CenterBox( 20, 69 );
lcol = lcol + 4;
say( trow + 4,lcol, "Switch! is setting a new standard in the memory switching" );
say( trow + 1, lcol, "world. With all the features provided there is no doubt -" );
say( trow + 1, lcol, "Switch! is the BEST memory switching function available" );
say( trow + 1, lcol, "at any price. After looking at what Switch! now does I'm" );
say( trow + 1, lcol, "sure you'll agree that Switch! is the one function no" );
say( trow + 1, lcol, "programmer should be without." );
say( trow + 2, lcol, "To register Switch! send $20.00* check or money order to:" );
say( trow+2,lcol+8 , "Curtis Little" );
say( trow+1,lcol+8 , "1087 Murrietta Blvd #244" );
say( trow+1,lcol+8 , "Livermore, CA 94550" );
say( trow+1,lcol+8 , "(415) 443-6438" );
say( trow + 2, lcol, "* Offer good through 9/1/89. Sorry, no COD orders accepted." );
v_fillca( Vline, 1, Color, ' ', Vcol );
v_putcur( Vline - 1, 1 );
exit(0);
}
/*
** CenterBox()
**
** This function draws the box I use centered on the screen
*/
CenterBox( int mheight, int mwidth )
{
int mindex;
trow = (Vline - mheight) / 2 + 1;
brow = trow + mheight - 1;
lcol = (Vcol - mwidth) / 2 + 1;
rcol = lcol + mwidth - 1;
v_clw( trow + 1, lcol + 1, brow - 1, rcol - 1, TXCOLOR );
v_drawbox( trow, lcol, mheight, mwidth, TXCOLORH );
/** Ok now the box is drawn and the inside is cleared. Draw the
** fancy stuff needed. Start with the shadow.
*/
v_fillca( brow + 1, lcol + 2, LIGHTGRAY << 4, 178, mwidth );
/* Draw the side shadow */
for ( mindex = trow + 1; mindex <= brow; mindex++ )
v_fillca( mindex, rcol + 1, LIGHTGRAY << 4, 178, 2 );
/* Draw in the top title for the box */
v_fillca( trow + 1, lcol + 1, TXCOLORH, 178, 6 );
v_putca( trow + 1, lcol + 7, TXCOLORH, 186 );
v_putca( trow, lcol + 7, TXCOLORH, 203 );
v_putca( trow + 1, rcol - 7, TXCOLORH, 186 );
v_fillca( trow + 1, rcol - 6, TXCOLORH, 178, 6 );
v_putca( trow, rcol - 7, TXCOLORH, 203 );
v_fillca( trow + 2, lcol + 1, TXCOLORH, 196, mwidth - 2 );
v_putca( trow + 2, lcol, TXCOLORH, 199 );
v_putca( trow + 2, rcol, TXCOLORH, 182 );
v_putca( trow + 2, lcol + 7, TXCOLORH, 208 );
v_putca( trow + 2, rcol - 7, TXCOLORH, 208 );
Center( trow + 1, RED << 4 | WHITE, " Switch! Copyright (C)1988-89 By Curtis Little " );
return(0);
}
/**
** PressAnyKey()
**
** This function prints a banner centered on the box at the bottom line
** and pauses for a key to be pressed.
*/
PressAnyKey( void )
{
Center( brow, CYAN << 4, " Press Any Key To Continue " );
return(v_getch());
}
/**
** SetScreen()
**
** This function sets up the screen for the demo.
*/
SetScreen( void )
{
v_fillca( 1, 1, LIGHTGRAY, 178, Vline * Vcol );
Center( 1, LIGHTGRAY << 4 | BLUE, " Switch! ∙ C Demonstration Program ∙ 03/26/89 " );
return(0);
}
/**
** Centered()
**
** This function prints a string centered on the specified row of the screen.
*/
Center( int mrow, int attr, char *mstr )
{
v_putsa( mrow, (Vcol - strlen( mstr )) / 2 + 1, attr, mstr );
}
/*
Fill in NULL functions to resolve externals referenced in the LIB that
aren't need for this demo.
*/
int v_setfreq( )
{
}
int v_delay( )
{
}